import {get,post} from '../../http'
import { message } from 'antd';

const FULLCAPACITY = 'FULLCAPACITY';
const DELECTOULL = 'DELECTOULL'

const initState={
	shipsList:{},
	delectRes:false
}

// reducer1
export function fullmenu(state=initState, action){
	switch(action.type){
		case FULLCAPACITY:
			return Object.assign({},state,{shipsList:action.data,delectRes:false})
		case DELECTOULL:
			return Object.assign({},state,{delectRes:action.res})
		default:
			return state
	}
} 

function fullCapacitySuccess(data){
	console.log(data)
	return {type:FULLCAPACITY,data:data}
}
function delectSuccess(res){
	if(res){
		message.success("删除运力成功")
	}else{
		message.warning("删除运力失败")
	}
	
	return {type:DELECTOULL,res:res}
}

export function fullCapacity(page,limit,rzState,monitoring,shipName){
	let data = {page:page,limit:limit,rzState:rzState,monitoring:monitoring,shipName:shipName}
	return dispatch=>{
		post('/ship/selectAllShips.do',data)
			.then(res=>{
					dispatch(fullCapacitySuccess(res.shipsList));
			})		
	}
	
}

export function delectCapacity(shipId){
	let data = {shipId:shipId}
	return dispatch=>{
		post('/ship/deleteShipsByShipid.do',data)
			.then(res=>{
				dispatch(delectSuccess(res.SUCCESS));
			})		
	}
	
}


